package spectra.ee.web.common.service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import spectra.base.BasePublic;
import spectra.base.licensemanager.Encrypt;
import spectra.base.log.Logger;
import spectra.ee.EEConfig;
import spectra.ee.commons.common.model.Attach;

public class AttachWebService extends AttachServiceBase
{
	/** Logger객체. */
    private static Logger logger = Logger.getLoggerInstance(AttachWebService.class.getName());
    
    /**
     * kbId(qnaId)에 해당하는 첨부파일 리스트를 가져오는 메소드
     */
    public List selectAttachList(Attach attach) throws Exception
    {
    	ArrayList listRet = new ArrayList();

        try
        {
            List list = (List) sqlMap.queryForList("Attach.selectAttachList", attach);
            
            if(list != null)
            {
            	
            	Attach attachBean = null;
            	String [] aFileInfo = new String[2];
            	String strEncText = "";
            	
            	for(int i = 0; i < list.size(); i++)
            	{
            		attachBean = (Attach) list.get(i);
            		
            		aFileInfo[0] = attachBean.getAttachPath();
    				aFileInfo[1] = attachBean.getAttachName();
    				
    				strEncText = Encrypt.crypt(aFileInfo, EEConfig.getEncryptKey(), BasePublic.ENCODING);
    				strEncText = java.net.URLEncoder.encode(strEncText);
    				
    				attachBean.setAttachPath(strEncText);
    				
    				listRet.add(attachBean);
            	}
            }
        }
        catch (SQLException e)
        {
            logger.error(e.getMessage());
            e.printStackTrace();
        }
        
        return listRet;
    }
}